﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Common.Web
{
    /// <summary>
    /// 缓存操作类
    /// </summary>
    public class Cache
    {
        /// <summary>
        /// 保存缓存
        /// </summary>
        /// <param name="key"></param>
        /// <param name="objs"></param>
        public void SetCache(string key, List<object> objs)
        {
            if (System.Web.HttpRuntime.Cache[key] == null)
            {
                System.Web.HttpRuntime.Cache.Insert(key, objs, null, DateTime.Now.AddHours(12), TimeSpan.Zero);
            }
            else
            {
                string errormsg = "保存缓存" + key + "失败，缓存中存在此对象";
            }
        }
        /// <summary>
        /// 获取缓存
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public List<object> GetCache(string key)
        {
            if (System.Web.HttpRuntime.Cache[key] != null)
            {
                return (System.Collections.Generic.List<object>)System.Web.HttpRuntime.Cache[key];
            }
            else
            {
                return null;
            }

        }
        /// <summary>
        /// 删除缓存
        /// </summary>
        /// <param name="key"></param>
        public void DelCache(string key)
        {
            System.Web.HttpRuntime.Cache[key] = null;
        }
    }
}
